<template>
  <div class="user-info">
    <el-dropdown>
      <span class="el-dropdown-link">
        <el-avatar
          :size="33"
          src="https://img-blog.csdnimg.cn/img_convert/c44557e91e69011385a02e707505b19a.png"
        ></el-avatar>
        <span class="user-name">{{ userName }}</span>
        <el-icon class="el-icon--right">
          <arrow-down />
        </el-icon>
      </span>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item @click="handleExitClick">退出登录</el-dropdown-item>
          <el-dropdown-item divided>用户信息</el-dropdown-item>
          <el-dropdown-item>系统管理</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent } from 'vue'
import { useStore } from '@/store'
import { useRouter } from 'vue-router'
export default defineComponent({
  name: 'userInfo',
  setup() {
    const store = useStore()
    const router = useRouter()
    const userName = computed(() => store.state.login.userInfo.name)
    const handleExitClick = () => {
      localStorage.removeItem('token')
      router.push('/main')
    }
    return { userName, handleExitClick }
  }
})
</script>

<style lang="less" scoped>
.user-info {
  width: 200px;
  // border: 1px solid red;
  .el-dropdown-link {
    display: flex;
    align-items: center;
    // border: 1px solid blue;
    .user-name {
      margin-left: 5px;
    }
  }
}
.example-showcase .el-dropdown-link {
  cursor: pointer;
  color: var(--el-color-primary);
  display: flex;
  align-items: center;
}
</style>
